package com.example.partner.adapter;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.example.partner.fragment.CommonConcernFragment;
import com.example.partner.fragment.UserInfoFragment;

import java.util.ArrayList;
import java.util.List;

public class ConcernViewPagerAdapter extends FragmentStateAdapter {
    private final List<Fragment> fragmentList = new ArrayList<>();


    public ConcernViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }
    // 添加 setFragments 方法
    public void setFragments(List<Fragment> fragments) {
        fragmentList.clear();
        fragmentList.addAll(fragments);
        notifyDataSetChanged();  // 通知数据已更改
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        Log.d("ViewPager", "Creating fragment at position: " + position);

        // 根据位置返回对应的Fragment
        switch (position) {
            case 0:
                return new UserInfoFragment();
            case 1:
                return new CommonConcernFragment();
        }
        return null;
    }

    @Override
    public int getItemCount() {
        return 2; // 标签总数
    }
}
